<template>
	<view>
		<cu-custom v-if="customShow" bgColor="bg-fafafa" :isBack="true">
			<block slot="backText"></block>
			<block slot="content"></block>
		</cu-custom>
		<scroll-view class="scrollPage bg-f7f7f7" scroll-y="true" :style="'height:'+(winHeight-barHeight)+'px'">
			<view class="login-logo">
				<image src="../../static/logo.png" style="width:230upx;height:230upx;"></image>
				<view class="text-baseColor text-30 text-bold" style="line-height:60upx;">XXX-CHAT</view>
			</view>
			
			<view class="btn-list">
				<view class="padding-bottom-safe">
					<view class="padding-lg" style="padding-top: 0;">
						<navigator class="cu-btn block bg-them round text-bold lg" style="font-size:26upx;" url="../../pages1/login/mobile">
							<image src="../../static/pwd_w.png" style="width:30upx;height:30upx;margin-right:5upx;"></image> 账号密码登录
						</navigator>
					</view>
					<view class="padding-lg" style="padding-top: 0;">
						<navigator class="cu-btn block lines-themeColor round text-bold lg" style="font-size:26upx;" url="../../pages1/login/captcha">
							<image src="../../static/captcha.png" style="width:30upx;height:30upx;margin-right:5upx;"></image> 验证码登录
						</navigator>
					</view>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex';
	import xcxObj from 'model/xcxModel.js'
	import userObj from 'model/userModel.js';
	let me = null;
	export default {
		data() {
			return {
				customShow:0,
				barHeight: 0,
				showPassword: true,
				mobile: '',
				pwd: '',
				isWXInstalled:0,
				login_data: {}
			};
		},
		onLoad() {
			me = this;
			this.barHeight = this.NativeBar;
			//#ifdef H5 || MP-BAIDU || MP-TOUTIAO || MP-WEIXIN
			this.customShow = 1;
			this.barHeight = this.CustomBar;
			//#endif
			
			// #ifdef APP-PLUS
			// if (plus.os.name == "iOS") {
			// 	var WXApi = plus.ios.import("WXApi");
			// 	if(WXApi.isWXAppInstalled()){
			// 		me.isWXInstalled = 1;
			// 	}
			// }
			// else{
			// 	me.isWXInstalled = 1;
			// }
			// #endif
			me.userInfoSync();
			
		},
		onShow() {},
		onReady() {
			//this.height = this.WindowHeight-this.CustomBar;
		},
		onHide() {},
		onUnload() {},
		computed: {
			...mapState({
				navHeight: ({
					baseModule
				}) => baseModule.navHeight,
				winHeight: ({
					baseModule
				}) => baseModule.winHeight,
				dToken: ({
					baseModule
				}) => baseModule.dToken,
				dClientid: ({
					baseModule
				}) => baseModule.dClientid,
				referrerId: ({
					baseModule
				}) => baseModule.referrerId
			})
		},
		methods: {
			...mapMutations(['userModule/login','userModule/setOpenId','userModule/setUnionId','userModule/setOrderAccepter']),
			userInfoSync() {
				var info = this.getUserInfo();
				if (info) {
					this['userModule/login'](info);
					this['userModule/setOrderAccepter'](me.getStore('orderAccepter'));
					uni.navigateBack({
						delta:1
					})
				}
			},
			xcxGetUserProfile(){
				uni.showLoading({
					title: '请稍后'
				});
				wx.getUserProfile({
					desc:'获取头像、昵称',
					success: function(res2) {
						var _wxxcxInfo = JSON.parse(res2.rawData);
						me.setStore("wxxcxInfo",_wxxcxInfo);
						wx.login({
						  success (res1) {
						    if (res1.code) {
							  uni.showLoading({
							  	title: '加载中'
							  });
							  xcxObj.getUserInfo(me,{
								code: res1.code,
							  	iv: res2.iv,
							  	encryptedData: res2.encryptedData,
							  	referrerId: me.referrerId
							  }).then(resData=>{
							  	if(resData.userInfo){
							  		me['userModule/login'](resData.userInfo);
							  		me['userModule/setOpenId'](resData.openId);
							  		me['userModule/setUnionId'](resData.unionId);
							  		me.setUserInfo(resData.userInfo);
							  		me.setStore("openId", resData.openId);
							  		me.setStore("unionId", resData.unionId);
							  		uni.hideLoading();
									uni.navigateBack({delta: 1});
							  	}
							  	else{
							  		me.setStore("openId", resData.openId);
							  		me.setStore("unionId", resData.unionId);
							  		_wxxcxInfo.openId = resData.openId;
							  		_wxxcxInfo.unionId = resData.unionId;
							  		me.setStore("wxxcxInfo",_wxxcxInfo);
							  		uni.navigateTo({
							  			url:'../../pages1/login/wxxcxBanding'
							  		})
							  	}
							  	uni.hideLoading();
							  }).catch(err=>{
							  	console.log('error:' + err)
							  	uni.hideLoading();
							  	uni.showToast({
							  		title: '授权登录失败',
							  		icon: 'none',
							  		duration: 1000
							  	});
							  });
						    } else {
						      console.log('登录失败:' + res.errMsg);
							  uni.showToast({
							  	title: '授权登录失败',
							  	icon: 'none',
							  	duration: 1000
							  });
						    }
						  }
						});
					},
					fail: function(errorMsg) {
						console.log('获取用户登录态失败:' + errorMsg)
						uni.hideLoading();
						uni.showToast({
							title: '授权登录失败',
							icon: 'none',
							duration: 1000
						});
					}
				});
			},
			wechatLogin(){}
		}
	}
</script>

<style>
	.login-logo image {
		width: 160upx;
		height: 160upx;
		/* margin-top: 16upx; */
	}

	.login-logo {
		text-align: center;
	}

	.btn-list {
		position: absolute;
		width: 100%;
		bottom: 0;
	}

	.iptp {
		height: 100upx;
		line-height: 100upx;
	}

	.solid-bottom .ipt {
		height: 100upx;
		margin-top: 17.2upx;
		line-height: 100upx;
		padding-left: 20upx;
	}

	.solid-bottom:after {
		border-bottom-color: #ff659b;
	}

	.showpwd {
		width: 100upx;
		height: 100upx;
		position: absolute;
		right: 0;
		line-height: 100upx;
		text-align: center;
		bottom: 0;
		z-index: 100;
	}
</style>
